#include <stdio.h>
#include "prop.h"

/*创建道具*/
prop* CreatProp(enum PropType type,void* ptr)
{
    prop* p = (prop*)malloc(sizeof(prop));
    if(p==NULL)
    return NULL;

    p->type = type;
    p->ptr = ptr;
    return p;
}
/*释放道具*/
void FreeProp(void* ptr,void(*Clearptr)(void*))
{
    prop* p = (prop*)ptr;
    Clearptr(p->ptr);
    free(p);
}


/*创建武器*/
weapon* CreatWeapon(int id,const char* name,int attack,enum Effect effect)
{
    weapon* w = (weapon*)malloc(sizeof(weapon));
    if(w==NULL)
    return NULL;
    w->name = GetString(name);
    w->attack = attack;
    w->id = id;
    w->effect = effect;
    return w;
}
/*初始化武器*/
void InitWeapon(weapon* w)
{
    InitString(&w->name);
    w->attack = 0;
    w->id = 0;
    w->effect =0;
}
/*武器状态保存到字符串*/
mystr WeaponToString(weapon* w)
{
    char str[1024] = {0};
    sprintf(str,"%d %s %d %d %d\n",Weapon,w->name.string,w->attack,w->id,w->effect);
    return GetString(str);
}


/*创建防具*/
defence* CreatDefence(int id,const char* name,int def,enum Effect effect)
{
    defence* d =(defence*)malloc(sizeof(defence));
    if(d==NULL)
    return NULL;
    d->name = GetString(name);
    d->defence = def;
    d->id = id;
    d->effect = effect;
    return d;
}
/*初始化防具*/
void InitArmor(defence* d)
{
    InitString(&d->name);
    d->defence = 0;
    d->id = 0;
    d->effect = 0;
}
/*防具状态保存到字符串*/
mystr ArmorToString(defence* d)
{
    char str[1024] = {0};
    sprintf(str,"%d %s %d %d %d\n",Defence,d->name.string,d->defence,d->id,d->effect);
    return GetString(str);  
}


/*创建消耗品*/
medicament* CreatItem(int id,const char* name,int hp,enum Effect effect)
{
    medicament* i =(medicament*)malloc(sizeof(medicament));
    if(i==NULL)
    return NULL;
    i->name = GetString(name);
    i->HP = hp;
    i->id = id;
    i->effect = effect;
    return i;
}
/*初始化消耗品*/
void InitItem(medicament* i)
{
    InitString(&i->name);
    i->HP = 0;
    i->id = 0;
    i->effect = 0;
}
/*将消耗品保存到字符串*/
mystr ItemToString(medicament* m)
{
    char str[1024] = {0};
    sprintf(str,"%d %s %d %d %d\n",Medicament,m->name.string,m->HP,m->id,m->effect);
    return GetString(str);  
}

 
